/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package m.ouachani;

import model.DAO;
import model.Medecin;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author mouachani
 */
public class AutreActivity extends ListActivity {

    public void onCreate(Bundle icicle) {

        super.onCreate(icicle);
        // on va chercher la vue
        setContentView(R.layout.autrevue);
        TextView label = (TextView) findViewById(R.id.label);
        Intent inter = getIntent();
        String dep = inter.getStringExtra("leDep");
        label.setText("Liste Des Médecins du : "+dep);

        final List<Medecin> l = DAO.getLesMeds(dep);

        MedAdapter adapter = new MedAdapter(l, this);
        setListAdapter(adapter);

        final EditText KeyInput = (EditText) findViewById(R.id.choix);
        Button button = (Button) findViewById(R.id.bouton);

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View argO) {

                List<Medecin> lesMedsCommencantPar = new ArrayList<Medecin>();
                for (Medecin unMed : l) {
                    // toLowerCase() met en minuscule un String donné
                    if (unMed.getNom().toLowerCase().startsWith(KeyInput.getText().toString().toLowerCase())) {
                        lesMedsCommencantPar.add(unMed);
                    }
                }
                MedAdapter adapter = new MedAdapter(lesMedsCommencantPar, getApplicationContext());
                setListAdapter(adapter);
            }
        });
    }
}
